home *** CD-ROM | disk | FTP | other *** search
- /*
- * Copyright (C) 1994, Silicon Graphics, Inc.
- * All Rights Reserved.
- *
- * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
- * the contents of this file may not be disclosed to third parties, copied or
- * duplicated in any form, in whole or in part, without the prior written
- * permission of Silicon Graphics, Inc.
- *
- * RESTRICTED RIGHTS LEGEND:
- * Use, duplication or disclosure by the Government is subject to restrictions
- * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
- * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
- * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
- * rights reserved under the Copyright Laws of the United States.
- */
- #include <stdio.h>
- #include <malloc.h>
- #include "Info.h"
- #include "Entry.h"
- #include "Utils.h"
-
- Info::Info()
- {
- _size = 0;
- _next = NULL;
- }
-
- Info::~Info()
- {
- }
-
- int
- Info::size()
- {
- return _size;
- }
-
- void
- Info::rewind()
- {
- // Redefine in subclass
- }
-
- Entry *
- Info::nextEntry()
- {
- // Redefine in subclass
- return NULL;
- }
-
- /**********************************************************************/
-
- MemoryInfo::MemoryInfo()
- {
- entries = new Entry();
- current = NULL;
- _day = _month = _year = 0;
- }
-
- MemoryInfo::~MemoryInfo()
- {
- freeData();
- }
-
- void
- MemoryInfo::rewind()
- {
- current = entries->next();
- }
-
- Entry *
- MemoryInfo::nextEntry()
- {
- Entry *ptr;
-
- if (current) {
- ptr = current;
- current = current->next();
- return ptr;
- } else {
- return NULL;
- }
- }
-
- int
- MemoryInfo::readDay(FILE *fd, int version)
- {
- int each, num;
- Entry *entry;
-
- if (!readInt(fd, &_day) ||
- !readInt(fd, &_month) ||
- !readInt(fd, &_year) ||
- !readInt(fd, &num)) {
- return 0;
- } else {
- for (each=0; each<num; each++) {
- entry = new Entry();
- entry->setDate(_day, _month, _year);
- if (entry->readEntry(fd, version)) {
- addEntry(entry);
- } else {
- delete entry;
- return 0;
- }
- }
- return 1;
- }
- }
-
- void
- MemoryInfo::writeDay(FILE *fd, int annotate)
- {
- Entry *entry;
-
- writeInt(fd, _day, annotate ? "Day" : NULL);
- writeInt(fd, _month, annotate ? "Month" : NULL);
- writeInt(fd, _year, annotate ? "Year" : NULL);
- writeInt(fd, _size, annotate ? "Number of Slot Entries" : NULL);
- entry = entries;
- while (entry->next()) {
- entry->next()->writeEntry(fd, annotate);
- entry = entry->next();
- }
- }
-
- void
- MemoryInfo::addEntry(Entry *entry)
- {
- Entry *ptr;
-
- ptr = entries;
- while (ptr->next() &&
- compareDates(ptr->next()->day(), ptr->next()->month(),
- ptr->next()->year(),
- entry->day(), entry->month(), entry->year()) <= 0) {
- ptr = ptr->next();
- }
- entry->setNext(ptr->next());
- ptr->setNext(entry);
- _size++;
- }
-
- int
- MemoryInfo::removeEntry(Entry *entry)
- {
- Entry *ptr;
-
- ptr = entries;
- while (ptr->next() && ptr->next() != entry) {
- ptr = ptr->next();
- }
- if (ptr->next() == entry) {
- ptr->setNext(entry->next());
- _size--;
- return 1;
- } else {
- return 0;
- }
- }
-
- void
- MemoryInfo::clear()
- {
- freeData();
- entries = new Entry();
- current = NULL;
- }
-
- void
- MemoryInfo::freeData()
- {
- Entry *ptr;
-
- while (entries) {
- ptr = entries;
- entries = ptr->next();
- delete ptr;
- }
- }
-
- int
- MemoryInfo::annotate()
- {
- Entry *ptr;
-
- ptr = entries;
- while (ptr->next()) {
- if (ptr->next()->annotate()) {
- return 1;
- }
- ptr = ptr->next();
- }
- return 0;
- }
-
- /**********************************************************************/
-